CREATE PROCEDURE [dbo].[ReportInvoiceByPersonForProject]
@ProjectName NVARCHAR (50), @EndDate DATETIME
AS
BEGIN
	select u.FullName, p.Name as Project, e.EntryDate, e.Duration, pm.HourlyRate, e.BillableHours as Billing, c.Name as Category, e.Description
	from EntryLog e inner join
	     Users u on e.UserID = u.UserID inner join
		 Projects p on e.ProjectID = p.ProjectID inner join
		 Categories c on e.CategoryID = c.CategoryID inner join
		 ProjectMembers pm on pm.ProjectID = p.ProjectID and pm.UserID = u.UserID
	where (e.EntryDate <= @EndDate) and (p.Name = @ProjectName) and (e.HasBeenBilled = 0) and (p.ProjectTypeID = 1 or p.ProjectTypeID = 2) and (e.BillingStateID = 2)
	order by Project, FullName, EntryDate	
END

